package com.company.book_store.web.servlet;

import com.company.book_store.pojo.User;
import com.company.book_store.service.Iuserservice;
import com.company.book_store.service.UserserviceImpl;
import com.company.book_store.util.SendEamil;
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.GeneralSecurityException;

@WebServlet("/email_return")
public class email_return extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String account = req.getParameter("account");
        String book_name = req.getParameter("book_name");
        System.out.println(account);
        System.out.println(book_name);
        Iuserservice service = new UserserviceImpl();
        User user = service.selectByaccount(account);
        String username = user.getName();
        String email = user.getEmail();
        SendEamil sendEamil = new SendEamil();
        try {
            sendEamil.sen(username,email,book_name);


        } catch (MessagingException e) {
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        } catch (javax.mail.MessagingException e) {
            e.printStackTrace();
        }

    }
}
